require.config({
	baseUrl: "./javascripts/library",
	path: {
		axios: "axios",
		countdown: "countdown",
		jquery: "jquery",
		slider: "slider",
		swiper: "swiper",
		tabs: "tabs",
	},
});
//banner
require(["jquery", "slider"], function ($, slider) {
	let slides = $(".slider-container");
	slides.each(function () {
		// $(this).slider({
		// 	direction: 1,
		// });
		slider.slider.call($(this), { direction: 1 });
	});
});
require(["swiper"], function (swiper) {
	// console.log(swiper);
	let swiper1 = new swiper("#swiper1", {
		loop: true,
		speed: 10000,
		slidesPerView: 5,
		// loopedSlides: 9,
		autoplay: {
			delay: 0,
		},
		// scrollbar: {
		// 	el: ".swiper-scrollbar",
		// },
	});
});

//选项卡功能
require(["jquery", "tabs"], function ($, tabs) {
	let btns_1 = $(".sec-5 .new-top .tab-head-item");
	let tabItem_1 = $(".sec-5 .new-top .tab-body .tab-body-inner");

	let btns_2 = $(".sec-3 .goods-1 .nav .title-list li");
	let tabItem_2 = $(".sec-3 .goods-detail .goods-list-container .goods-list");
	tabs.tabs({
		btns: btns_1,
		items: tabItem_1,
		ev: "hover",
	});
	tabs.tabs({
		btns: btns_2,
		items: tabItem_2,
		ev: "hover",
	});
});

//倒计时功能
require(["jquery", "countdown"], function ($, countdown) {
	let countDownHour = $(".sec-2 .timer-unit-hour");
	let countDownMinute = $(".sec-2 .timer-unit-minute");
	let countDownSecond = $(".sec-2 .timer-unit-second");
	let timer = setInterval(() => {
		countDownHour.text(countdown.countDown(new Date("2021/12/23/22:30:00")).hour);
		countDownMinute.text(countdown.countDown(new Date("2021/12/23/22:30:00")).minute);
		countDownSecond.text(countdown.countDown(new Date("2021/12/23/22:30:00")).second);
	}, 1000);
});

//商品渲染
require(["jquery", "axios"], function ($, axios) {
	let goodsContainer = $(".sec-7 .more-inner");
	axios.get("/goods/goodslist").then((response) => {
		let data = response.data;
		if (data.success) {
			let temp = "";
			data.data.forEach(function (el) {
				console.log(JSON.parse(el.picture));
				temp += `	<div class="more-item">
							<a href="/goods-detail.html?id=${el.id}" class="img-container">
								<img src="${JSON.parse(el.picture)[0].src}" alt="${JSON.parse(el.picture)[0].alt}">
								<div class="mask"></div>
							</a>
							<div class="more-info">
								<p class="more-info-name">
									<span class="more-info-self">自营</span>${el.title}
								</p>
								<div class="more-info-price">
									<div class="mod-price">
										<span class="rmb">￥</span>
										<span class="price-text">${el.price}<span class="price-text-decimal">.00</span></span>
									</div>
									<div class="more-price-plus">券</div>
								</div>
							</div>
							<div class="more-item-delete">
							</div>
							<div class="more-item-hd">
								<a href="" class="more-find">
									<span class="more-find-icon"></span>
									<span>找相似</span>
								</a>
							</div>
				</div>`;
			});
			goodsContainer.append(temp);
		}
	});
});
